using System;
using System.Collections.Generic;

namespace DA.AnimGraph.Editor {

    internal class PerkMenuItemDefine {
        public string menuName;
        public Type agaPerkType;
        public PerkMenuItemDefine(string menuName, Type agaPerkType) {
            this.menuName = menuName;
            this.agaPerkType = agaPerkType;
        }
    }

    internal static class PerkDefine {

        // 各节点类别对应可用的perk
        public readonly static PerkMenuItemDefine[] perks_SampleNode = new PerkMenuItemDefine[] {
            new("Timeline", typeof(AGAPerk_Timeline)),
            new("Sync Group", typeof(AGAPerk_SyncGroup)),
        };
        public readonly static PerkMenuItemDefine[] perks_BlendNode = new PerkMenuItemDefine[] {
            new("Timeline", typeof(AGAPerk_Timeline)),
        };
        public readonly static PerkMenuItemDefine[] perks_SlotNode = new PerkMenuItemDefine[] {
            new("Timeline", typeof(AGAPerk_Timeline)),
        };

        /// <summary>
        /// 通过节点类别查找perk
        /// </summary>
        public readonly static Dictionary<Type, PerkMenuItemDefine[]> nodeToPerks = new Dictionary<Type, PerkMenuItemDefine[]>() {
            { typeof(AGANode_SampleBase), perks_SampleNode },
            { typeof(AGANode_BlendBase), perks_BlendNode },
            { typeof(AGANode_Slot), perks_SlotNode },
        };

        /// <summary>
        /// 查询节点类型对应的perk类型
        /// 定义注意避免重复，会将满足条件的数组拼接，没有进行去重
        /// </summary>
        /// <param name="agaNodeType">AGA节点类型</param>
        /// <returns></returns>
        public static PerkMenuItemDefine[] GetAvailablePerks(Type agaNodeType) {
            var outPerks = new List<PerkMenuItemDefine>();
            foreach (var kv in nodeToPerks) {
                if (agaNodeType.IsSubclassOf(kv.Key) || agaNodeType == kv.Key) {
                    outPerks.AddRange(kv.Value);
                }
            }
            if (outPerks.Count == 0) return null;
            return outPerks.ToArray();
        }
    }
}
